//
//  FirstLaunchViewController.m
//  ZGSHGYS
//
//  Created by hnb on 2016/11/18.
//  Copyright © 2016年 yncc. All rights reserved.
//

#import "FirstLaunchViewController.h"
#import "ViewController.h"

@interface FirstLaunchViewController ()<UIScrollViewDelegate,UIPageViewControllerDelegate>
@property (nonatomic,strong) UIScrollView *scrollerView;
@property (nonatomic,strong) UIPageControl *pageControl;
@property (nonatomic,copy) NSString *imgName;
@end

@implementation FirstLaunchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _imgName = @"";
    for (int i=0; i<3; i++) {
        
        UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth*i, 0, ScreenWidth, ScreenHeight)];
        if (IsiPhone4) {
            self.imgName= [NSString stringWithFormat:@"guide960_%i",i+1];
        }else if (IsiPhone5){
            self.imgName = [NSString stringWithFormat:@"guide1136_%i",i+1];
        }else if (IsiPhone6){
            self.imgName = [NSString stringWithFormat:@"guide1334_%i",i+1];
        }else if (IsiPhone6P){
            self.imgName = [NSString stringWithFormat:@"guide2208_%i",i+1];
        }
        imageView.tag = i;
        [imageView setImage:[UIImage imageNamed:self.imgName]];
        [self.scrollerView addSubview:imageView];
    }
    
    UIButton *btnClick=[UIButton buttonWithType:UIButtonTypeCustom];
    btnClick.tag = 10;
    [btnClick setFrame:CGRectMake(0,0, ScreenWidth*0.4, 40)];
    [btnClick setCenter:CGPointMake(ScreenWidth*2+ScreenWidth/2, ScreenHeight-100)];
    btnClick.layer.cornerRadius = 15;
    [btnClick setTitle:@"启动应用" forState:(UIControlStateNormal)];
    [btnClick setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    [btnClick setBackgroundColor:[UIColor colorWithRed:0.289 green:0.760 blue:0.447 alpha:1.000]];
    [btnClick addTarget:self action:@selector(scrollImgClick) forControlEvents:UIControlEventTouchUpInside];
    [self.scrollerView addSubview:btnClick];
    self.pageControl.numberOfPages = 3;
}
-(UIScrollView *)scrollerView{
    if (!_scrollerView) {
        _scrollerView = [[UIScrollView alloc]init];
        _scrollerView.frame = CGRectMake(0, 0, ScreenWidth,ScreenHeight);
        _scrollerView.delegate = self;
        _scrollerView.showsVerticalScrollIndicator = NO;
        _scrollerView.showsHorizontalScrollIndicator = NO;
        _scrollerView.contentSize=CGSizeMake(ScreenWidth*3,ScreenHeight);
        _scrollerView.pagingEnabled=YES;
        [self.view addSubview:_scrollerView];
    }
    return _scrollerView;
}
-(UIPageControl *)pageControl{
    if (!_pageControl) {
        _pageControl = [[UIPageControl alloc]init];
        _pageControl.center = CGPointMake(self.view.bounds.size.width/2, [UIScreen mainScreen].bounds.size.height-40);
        _pageControl.pageIndicatorTintColor = [UIColor colorWithRed:0.925 green:0.918 blue:0.953 alpha:1.000];
        _pageControl.currentPageIndicatorTintColor = [UIColor colorWithRed:0.289 green:0.760 blue:0.447 alpha:1.000];
        [self.view addSubview:_pageControl];
    }
    return _pageControl;
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    int pageCount = scrollView.contentOffset.x/[UIScreen mainScreen].bounds.size.width;
    self.pageControl.currentPage = pageCount;
}
-(void)scrollImgClick{
    ViewController *Vc = [ViewController new];
    [self presentViewController:Vc animated:YES completion:nil];
}

@end
